//
//  HNSH_GroupManageSwitchCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/18.
//

#import "HNSH_GroupManageSwitchCell.h"

@interface HNSH_GroupManageSwitchCell ()
/** */
@property (nonatomic, strong)UILabel * titleLabel;
/** */
@property (nonatomic, strong)UILabel * desLabel;
@end

@implementation HNSH_GroupManageSwitchCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor appWhiteLabelColor];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.desLabel];
    [self.contentView addSubview:self.switchView];
}

- (void)addAllLayout{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(6);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(22);
    }];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.right.mas_equalTo(-106);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(34);
    }];
    [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}

//MARK: Setter Methods
- (void)setDic:(NSDictionary *)dic{
    _dic = dic;
    
    self.titleLabel.text = dic[@"title"];
    self.desLabel.text = dic[@"des"];
    self.switchView.on = [dic[@"isOn"] boolValue];
}

//MARK: Getter Methods
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

- (UILabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [UILabel new];
        _desLabel.font = [UIFont systemFontOfSize:12];
        _desLabel.textColor = [UIColor appGrayLabelColor];
        _desLabel.numberOfLines = 0;
    }
    return _desLabel;
}

- (UISwitch *)switchView{
    if (!_switchView) {
        _switchView = [UISwitch new];
        _switchView.onTintColor = [UIColor appGreenColor];
    }
    return _switchView;
}

@end
